<template>
	<view class="container">
		<view class="user-info">
			<view class="avatar">
				<image :src="userInfo.avatarUrl || '/static/logo.png'" mode="aspectFill"></image>
			</view>
			<view class="info">
				<text class="name">{{userInfo.nickName || '未登录用户'}}</text>
				<text class="role">校园保安</text>
			</view>
		</view>
		
		<view class="card">
			<view class="card-item" @click="navTo('/pages/my/profile')">
				<text class="item-name">个人资料</text>
				<text class="arrow">></text>
			</view>
			<view class="card-item" @click="navTo('/pages/my/statistics')">
				<text class="item-name">工作统计</text>
				<text class="arrow">></text>
			</view>
			<view class="card-item" @click="navTo('/pages/my/schedule')">
				<text class="item-name">排班表</text>
				<text class="arrow">></text>
			</view>
		</view>
		
		<view class="card">
			<view class="card-item" @click="navTo('/pages/my/notice')">
				<text class="item-name">通知公告</text>
				<text class="arrow">></text>
			</view>
			<view class="card-item" @click="navTo('/pages/my/help')">
				<text class="item-name">使用帮助</text>
				<text class="arrow">></text>
			</view>
			<view class="card-item" @click="navTo('/pages/my/about')">
				<text class="item-name">关于系统</text>
				<text class="arrow">></text>
			</view>
		</view>
		
		<view class="logout-btn" @click="logout">退出登录</view>
		
		<view class="version">当前版本：v1.0.0</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userInfo: {
					nickName: '未登录用户',
					avatarUrl: '/static/logo.png'
				}
			}
		},
		// 页面加载时获取用户信息
		onShow() {
			this.getUserInfo();
		},
		methods: {
			// 获取登录用户信息
			getUserInfo() {
				try {
					const userInfoStorage = uni.getStorageSync('userInfo');
					if (userInfoStorage) {
						this.userInfo = userInfoStorage;
						console.log('获取到用户信息', this.userInfo);
					} else {
						console.log('未找到用户信息，可能未登录');
						// 未登录时重定向到登录页
						uni.redirectTo({
							url: '/pages/login/index'
						});
					}
				} catch (e) {
					console.error('获取用户信息失败', e);
				}
			},
			navTo(url) {
				uni.navigateTo({
					url: url
				});
			},
			logout() {
				uni.showModal({
					title: '提示',
					content: '确定要退出登录吗？',
					success: (res) => {
						if (res.confirm) {
							// 清除登录信息
							uni.removeStorageSync('userInfo');
							uni.removeStorageSync('token');
							
							// 提示退出成功
							uni.showToast({
								title: '已退出登录',
								icon: 'success',
								duration: 1500
							});
							
							// 返回登录页
							setTimeout(() => {
								uni.reLaunch({
									url: '/pages/login/index'
								});
							}, 1500);
						}
					}
				});
			}
		}
	}
</script>

<style lang="scss">
	.container {
		padding: 30rpx;
		background-color: #f5f6fa;
		min-height: 100vh;
	}
	
	.user-info {
		background-color: #fff;
		border-radius: 20rpx;
		padding: 40rpx 30rpx;
		display: flex;
		align-items: center;
		box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
		margin-bottom: 30rpx;
	}
	
	.avatar {
		width: 120rpx;
		height: 120rpx;
		border-radius: 60rpx;
		overflow: hidden;
		margin-right: 30rpx;
		background-color: #f0f0f0;
	}
	
	.avatar image {
		width: 100%;
		height: 100%;
	}
	
	.info {
		flex: 1;
	}
	
	.name {
		font-size: 36rpx;
		font-weight: bold;
		color: #333;
		margin-bottom: 10rpx;
		display: block;
	}
	
	.role {
		font-size: 28rpx;
		color: #666;
		display: block;
	}
	
	.card {
		background-color: #fff;
		border-radius: 20rpx;
		box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
		margin-bottom: 30rpx;
		overflow: hidden;
	}
	
	.card-item {
		height: 100rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 0 30rpx;
		border-bottom: 1px solid #f5f5f5;
	}
	
	.card-item:last-child {
		border-bottom: none;
	}
	
	.item-name {
		font-size: 30rpx;
		color: #333;
	}
	
	.arrow {
		font-size: 24rpx;
		color: #999;
	}
	
	.logout-btn {
		height: 90rpx;
		background-color: #fff;
		border-radius: 45rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		color: #ff3b30;
		font-size: 32rpx;
		margin: 60rpx 0;
		box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
	}
	
	.version {
		text-align: center;
		font-size: 24rpx;
		color: #999;
	}
</style> 